20. Run the Game!

Run the game!

1. Edit Run Configurations

Right now, there is a lot of code in this project and IntelliJ needs to be told what to run. To tell it to run Game.java, you need to go to Run > Edit Configurations, and set up a New configuration.

Edit config drop down menu

Edit Configurations... drop down menu.

Edit Configurations… drop down menu.

step 2

Then in the Run Configurations window, click the + button at the top left of this window to add a new configuration, and select Application.

Select new application

Add new Application configuration.

Add new Application configuration.

step 3

Then you'll see this configurations window, and the first thing you want to do is to name your configuration, and I'll name this Run Game.

Then you'll see the four fields that we've seen before:

  1. The main class that we want to run.
  2. The project directory for Project 1 - TicTacToe.
  3. The classpath of the module.
  4. The version of Java you're using.

You'll want to make sure these are all set to the correct fields before moving on and running the game. You'll also need to select the correct main class and module; the project directory and version of Java should be automatically chosen by IntelliJ.

So, after changing the name, the first thing you should select is the Main class by clicking the ... to the side of the Main class field. Then, a window will prompt you to select the Game class. Select this and click Okay.

Main class, Game.java

Main class selection screen.

Main class selection screen.

step 4

Next select the correct module by using the drop-down menu to the right of this field, and choose the Project_1_-_TicTacToe_main module. Make sure you select the main module and not the test or default project modules.

Module selection

Module selection.

Module selection.

step 5

So, your final configuration should have the following fields:

  1. The main class that we want to run should be com.udacity.Game.
  2. The project directory for Project 1 - TicTacToe (left as is).
  3. The classpath of the module, which should be Project_1_-_TicTacToe_main.
  4. The version of Java you're using, which should be version 8.

Correct run config

Correct run configuration.

Correct run configuration.

step 6

Make sure all of these fields are correct and match the picture before proceeding.

After you've named and set your configuration to run Game.java, click Apply then Okay to get back to your program.

Apply button

Click Apply... then Okay!

Click Apply… then Okay!

step 6 plus

2. Run the Game!

After your run configuration is set up, you should see it's name appear in the top right of your screen next to the Run button. Now, you can simply click this button and Game.java will run.

Run Game

Run Game button.

Run Game button.

running 1

When you click Run, you should see a tic tac toe grid appear!

Tic tac toe grid

Tic Tac Toe!

Tic Tac Toe!

tic tac toe grid

You can even play a one or two player game of Tic Tac Toe, but this game code does not yet detect when a player wins!